<?php
class MSEP_Ftp extends MSEP_Object
{


      private $mode;



      private $_conn_id;



      public function __init(MSEP $core)
      {
            $this->core = $core;

            $this->mode = FTP_ASCII;

            $this->_conn_id = "";
      }



      public function connect($user_name, $user_pass, $server)
      {
            if (($conn_id = ftp_connect($server)) !== false)
            {
                  $this->_conn_id = $conn_id;

                  if (@ftp_login($this->_conn_id, $user_name, $user_pass))
                  {
                        return true;
                  }

                  $this->close();
            }

            return false;
      }



      public function close()
      {
            ftp_close($this->_conn_id);
      }



      public function mode($mode)
      {
            if ($mode == "binary")
            {
                  $this->mode = FTP_BINARY;
            }
            else
            {
                  $this->mode = FTP_ASCII;
            }

            return $this;
      }



      public function upload($local_file, $remote_dir)
      {
            if (file_exists($local_file))
            {
                  $remote_file = $remote_dir.basename($local_file);

                  if (substr($local_file, 0, 1) == ".")
                  {
                        $local_file = getcwd().substr($local_file, 1);
                  }

                  if (ftp_put($this->_conn_id, $remote_file, $local_file, $this->mode))
                  {
                        return true;
                  }
            }

            return false;
      }

}
?>